<!DOCTYPE html>
<html lang="en">

<include file="CommonSidebar:common-head"/>
<link rel="stylesheet" href="__ROOT__/Application/Admin/Public/css/common.css">
<link href="__ROOT__/Application/Admin/Public/css/jquery.datetimepicker.css" rel="stylesheet">
<body>

<div id="wrapper">

    <!-- Navigation -->
    <include file="CommonSidebar:common-navbar"/>

    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h2 class="page-header">
                    {$WZDATA.P}-{$WZDATA.C}-{$WZDATA.Z}-{$WZDATA.ADDRESS}-{$WZDATA.NAME}-{$WZDATA.SJCODE}-{$WZDATA.SGCODE}-书柜中的所有书籍</h2>
           <h3>书柜编号:{$BHCODE}</h3>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
                    <div class="panel panel-default">
                        <div class="panel-heading" role="tab" id="headingOne">
                            <h4 class="panel-title">
                                <a role="button" data-toggle="collapse" data-parent="#accordion"
                                   href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                                    操作栏
                                </a>
                            </h4>
                        </div>
                        <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel"
                             aria-labelledby="headingOne">
                            <div class="panel-body">
                                <div class="form-horizontal">

                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">ISBN</label>

                                        <div class="col-sm-4">
                                            <input class="form-control" id="ISBN" name="ISBN">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">书籍移动</label>

                                        <div class="col-sm-2">
                                            <button class="form-control btn btn-warning btn-xs" onclick="ShowWz();">
                                                mobile
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12">

                <div class="row">
                    <div class="col-md-12">
                        <div class="panel-body">
                            <div class="dataTable_wrapper">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                    <tr>
                                        <th style="text-align:center"><input name="all_checkbox" type='checkbox'
                                                                             id="all_checkbox"></th>

                                        <th style="text-align:center"width="12%">条形码</th>
                                        <th style="text-align:center" width="20%">书名</th>
                                        <th style="text-align:center" width="8%">成色</th>
                                        <th style="text-align:center" width="8%">作者</th>
                                        <th style="text-align:center" width="8%">出版社</th>
                                        <th style="text-align:center">包装</th>
                                        <th style="text-align:center">所属</th>
                                        <th style="text-align:center">状态</th>
                                        <th style="text-align:center" width="15%">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <foreach name="DATA" item="v" key="k">
                                        <tr class="odd gradeX">
                                            <if condition="$v['BOOK_ID']">
                                                <td></td>
                                                <else/>
                                                <td><input type='checkbox' data-id="{$v.ID}" name="checkbox"
                                                           value="{$v.WZ_ID}"></td>
                                            </if>
                                            <td>{$v.ISBN}</td>
                                            <td>{$v.TITLE}</td>
                                            <td>{$v.GG_NAME}</td>
                                            <td>{$v.AUTHOR}</td>
                                            <td>{$v.PRESS}</td>
                                            <td>{$v.PACKING_SPECIFICATION}</td>
                                            <if condition="$v.USER_ID != null">
                                            <td><a class=" btn btn-warning btn-xs" target="_blank" href="{:U('User/Index')}?user_id={$v.USER_ID}">查看</a></td>
                                                <else/>
                                                <td>奇妙阅</td>
                                            </if>
                                            <if condition="$v.SXJ == 1">
                                                <td style="color: #008200" data-id="{$v.ID}" data-shelves="{$v.SXJ}"
                                                    onclick="updateShelves($(this))">上架中
                                                </td>
                                                <else/>
                                                <td data-id="{$v.ID}" data-shelves="{$v.SXJ}" style="color: red"
                                                    onclick="updateShelves($(this))">已下架
                                                </td>
                                            </if>
                                            <td class="center" style="text-align:center">
                                                <a class="goods-edit text-info" target="_blank"
                                                   href="{:U('Book/EditBookIndex')}?ID={$v.ID}&BHCODE={$BHCODE}">编辑</a>
                                                <-->
                                                <a class="goods-edit text-info" onclick="ycwz({$v['WZ_ID']},$(this))">从书柜中移除</a>
                                            </td>
                                        </tr>
                                    </foreach>
                                    </tbody>
                                </table>
                            </div>
                            <!-- /.table-responsive -->
                        </div>

                    </div>
                </div>


            </div>
        </div>

    </div>
</div>


<!--选择仓库位置-->
<div id="cityModal" class="modal fade bs-example-modal-sm" data-backdrop='static' tabindex="-1" role="dialog"
     aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true" style="font-size:35px">&times;</span></button>
                <h3 class="modal-title text-center">选择要移动到的位置</h3>

                <div class="row col-xs-4">
                    <span class="btn btn-primary " onclick="YDSBOOKCK()">移动到收书数据库</span>
                </div>
                <input type="hidden" id="LEVEL">
            </div>
            <div class="modal-body" style="padding-top:0px;padding-bottom:5px;">
                <div class="row" id="city-content" style="height:530px;overflow-y:scroll;">
                    <div class="col-xs-4 spell-list"
                         style="height:100%; background:#f0f0f0; overflow-y:scroll; overflow-x:hidden; -webkit-overflow-scrolling:touch">
                        <div class="row">
                            <foreach name="CKDATA" item="v" key="k">
                                <div class="col-xs-12 type-item " data-type="{$v.BHCODE}" data-align="sj">
                                    <h5>
                                        <span>{$v.NAME}</span>
                                        <span class="glyphicon glyphicon-menu-right" style="float:right;"></span>
                                    </h5>
                                </div>
                            </foreach>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--选择仓库位置-->

<!--书籍列表-->
<div id="BOOKLIST" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog"
     aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title text-center">书籍列表</h4>
            </div>
            <div class="modal-body">
                <table id="my-orders" class="table table-responsive table-bordered" style="margin-top: 10px"
                       border="0">
                    <tr style="color: #008200;color-interpolation: red;align-content: center">
                        <th width="5px" style="text-align:center"></th>
                        <th style="text-align:center">图片</th>
                        <th style="text-align:center" width="200px">书名</th>
                        <th style="text-align:center">成色</th>
                        <th style="text-align:center">成色售价</th>
                        <th style="text-align:center">成色库存</th>
                        <th style="text-align:center">作者</th>
                        <th style="text-align:center">出版社</th>
                        <th style="text-align:center">包装</th>
                        <th style="text-align:center">定价</th>
                    </tr>
                    <tbody id="context">
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<!--书籍列表-->

<include file="CommonSidebar:common-script"/>
<script src="__ROOT__/Application/Admin/Public/js/jquery.datetimepicker.js"></script>
<!-- DataTables JavaScript -->
<script src="__ROOT__/Application/Admin/Public/bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
<script src="__ROOT__/Application/Admin/Public/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>

<!-- Custom Theme JavaScript -->
<script src="__ROOT__/Application/Admin/Public/dist/js/sb-admin-2.js"></script>
<!-- Page-Level Demo Scripts - Tables - Use for reference -->


<script type="text/javascript" src="__ROOT__/Application/Admin/Public/LoadPading/LoadPading.js?v=3"></script>
<link rel="stylesheet" href="__ROOT__/Application/Admin/Public/LoadPading/LoadPading.css" type="text/css"
      media="screen"/>


<script>

    $(document).ready(function () {
        $('#ISBN').focus();
    });


    // 绑定键盘按下事件
    $(document).keypress(function (e) {
        // 回车键事件
        if (e.which == 13  && $('#BOOKLIST').hasClass('in')) {
            var GG_ID = '';
            var WZ_CODE = '{$BHCODE}';
            $("input[name='checkbox_s']:checkbox:checked").each(function (index, item) {
                GG_ID = $(this).val();
            });
            $.post("{:U('BookAddWZ')}",
                    {GG_ID: GG_ID,WZ_CODE:WZ_CODE},
                    function (data) {
                        console.log(data);
                        if(data){
                            alert('添加成功');
                            window.location.reload();
                        }else{
                            alert('添加失败');
                        }
                    });
        }

    });



    //输入框回车事件
    $("#ISBN").keydown(function (e) {
        var ISBN = $(this).val();
        if (e.keyCode == 13) {
            $.post("{:U('GetBookToISBN')}", {ISBN: ISBN}, function (data) {
                console.log(data);
                if (data) {
                    $("#context").html("");
                    for (var i in data) {
                        var html = '';
                        html += '<tr>';
                        if (i == 0) {
                            html += "<td ><input name='checkbox_s' value='" + data[i]['GG_ID'] + "' type='checkbox' checked></td>";
                        } else {
                            html += "<td ><input name='checkbox_s' value='" + data[i]['GG_ID'] + "' type='checkbox'></td>";
                        }
                        html += '<td ><img width="50px" src="' + data[i]['PIC_URL'] + '"></td>';
                        html += '<td >' + data[i]['TITLE'] + '</td>';
                        html += '<td >' + data[i]['GG_NAME'] + '</td>';
                        html += '<td >' + data[i]['GG_PRICE'] + '</td>';
                        html += '<td >' + data[i]['GG_NUM'] + '</td>';
                        html += '<td >' + data[i]['AUTHOR'] + '</td>';
                        html += '<td >' + data[i]['PRESS'] + '</td>';
                        html += '<td >' + data[i]['PACKING_SPECIFICATION'] + '</td>';
                        html += '<td >' + data[i]['Y_PRICE'] + '</td>';
                        html += '</tr>';
                        $("#context").append(html);
                    }
                    $('#BOOKLIST').modal('show');
                }
            });
        }
    });

    var ydvals = [];//书柜移动参数
    var ydsbooks = [];//收书数据库移动参数

    //移动位置弹窗
    function ShowWz() {
        ydvals = [];
        ydsbooks = [];
        $("input[name='checkbox']:checkbox:checked").each(function (index, item) {
            var WZ_ID = $(this).val();
            var BOOK_ID = $(this).attr('data-id');
            ydvals.push(WZ_ID);
            ydsbooks.push(BOOK_ID);
        });
        if (ydvals.length <= 0) {
            alert('请选择书籍');
            return 0;
        } else {
            alert('您本移动操作一共选择了：' + ydvals.length + '本书籍');
        }
        console.log(ydsbooks);
        $('#cityModal').modal("show");
    }

    //位置选择事件
    $(document).on("click", ".type-item", function () {
        var BOOK_ID = $("#BOOK_ID").val();
        var $elem = $(this);
        var ID = $elem.attr("data-type");
        var name = $elem.attr("data-align");
        var LEVEL = $('#LEVEL').val();
        if (name == 'wz') {
            if (confirm('确认书籍转移???')) {
                $.post("{:U('StoreHouse/Select')}",
                        {ID: ID, name: name, BOOK_ID: BOOK_ID, YDWZS: ydvals},
                        function (data1) {
                            console.log(data1);
                            if (data1['datas'].length > 0) {
                                var data = data1['datas'];
                                $elem.siblings().css('color', '#777');
                                $elem.css('color', '#000079');
                                var $cities = $elem.parent().parent();
                                $elem.parent().parent().nextAll().remove();
                                /*active*/
                                var html = '';
                                html += ' <div class="col-xs-4 spell-list" style="height:100%; background:#f0f0f0; overflow-y:scroll; overflow-x:hidden; -webkit-overflow-scrolling:touch">' +
                                        ' <div class="row">';
                                for (var i = 0; i < data.length; i++) {
                                    html += '<div class="col-xs-12 type-item " data-type="' + data[i]['BHCODE'] +
                                            '" data-align="' + data1['name'] + '">' +
                                            '<h5>' +
                                            '<span>' + data[i]['CODE'] + '</span>' +
                                            '<span  class="glyphicon glyphicon-menu-right" style="float:right;"></span>' +
                                            '</h5>' +
                                            '</div>';
                                }
                                html += '</div>' +
                                        '</div>';
                                $cities.after(html);
                            } else {
                                if (data1['name'] == '1' && data1['OK']) {
                                    alert('添加成功');
                                    window.location.reload()
                                } else {
                                    alert('成功转移书籍数：' + data1['OK']);
                                    if (data1['OK']) {
                                        if (confirm('是否前往目标书柜？')) {
                                            window.location.href = "{:U(StoreHouse/Bookindex)}?BHCODE=" + data1['BHCODE'];
                                        } else {
                                            window.location.reload();

                                        }
                                    } else {
                                        window.location.reload();
                                    }
                                }
                                $('#cityModal').modal("hide");

                            }


                        });
            }
        } else {
            $.post("{:U('StoreHouse/Select')}",
                    {ID: ID, name: name, BOOK_ID: BOOK_ID, YDWZS: ydvals},
                    function (data1) {
                        console.log(data1);
                        if (data1['datas'].length > 0) {
                            var data = data1['datas'];
                            $elem.siblings().css('color', '#777');
                            $elem.css('color', '#000079');
                            var $cities = $elem.parent().parent();
                            $elem.parent().parent().nextAll().remove();
                            /*active*/
                            var html = '';
                            html += ' <div class="col-xs-4 spell-list" style="height:100%; background:#f0f0f0; overflow-y:scroll; overflow-x:hidden; -webkit-overflow-scrolling:touch">' +
                                    ' <div class="row">';
                            for (var i = 0; i < data.length; i++) {
                                html += '<div class="col-xs-12 type-item " data-type="' + data[i]['BHCODE'] +
                                        '" data-align="' + data1['name'] + '">' +
                                        '<h5>' +
                                        '<span>' + data[i]['CODE'] + '</span>' +
                                        '<span  class="glyphicon glyphicon-menu-right" style="float:right;"></span>' +
                                        '</h5>' +
                                        '</div>';
                            }
                            html += '</div>' +
                                    '</div>';
                            $cities.after(html);
                        } else {
                            if (data1['name'] == '1' && data1['OK']) {
                                alert('添加成功');
                                window.location.reload()
                            } else {
                                alert('成功转移书籍数：' + data1['OK']);
                                if (data1['OK']) {
                                    if (confirm('是否前往目标书柜？')) {
                                        window.location.href = "{:U(StoreHouse/Bookindex)}?BHCODE=" + data1['BHCODE'];
                                    } else {
                                        window.location.reload();

                                    }
                                } else {
                                    window.location.reload();
                                }
                            }
                            $('#cityModal').modal("hide");

                        }


                    });
        }

    });

    //移动到收书数据库
    function YDSBOOKCK() {

        $.post("{:U('YDSBOOKCK')}",
                {BOOKIDS: ydsbooks},
                function (data) {
                    console.log(data);
                    if (data > 0) {
                        alert('成功转移书籍');
                        if (confirm('成功转移书籍,是否前往收书数据库')) {
                            window.location.href = "{:U('SBook/Index')}";
                        } else {
                            window.location.reload();

                        }
                    } else {
                        alert('失败,书籍已经存在');
                    }
                });
    }

    //上-下架
    function updateShelves($elem) {
        var id = $elem.attr("data-id");
        var shelves = $elem.attr("data-shelves");

        var str = "";
        var newshelves = "";
        if (shelves == 0) {
            str = "确定上架该书籍吗？";
            newshelves = 1;
        } else {
            str = "确定下架该书籍吗？";
            newshelves = 0;
        }
        if (confirm(str)) {
            $.post("{:U('Book/updateShelves')}",
                    {ID: id, SXJ: newshelves},
                    function (data) {
                        if (parseInt(data) == 1) {
                            if (newshelves == 1) {
                                $elem.attr("data-shelves", 1);
                                $elem.html('上架中');
                                $elem.css('color', '#008200');
                            } else {
                                $elem.attr("data-shelves", 0);
                                $elem.css('color', 'red');
                                $elem.html('已下架');
                            }
                            alert('修改成功');
                        } else {
                            alert('修改失败');
                        }
                    });
        }


    }

    //    移除位置
    function ycwz(ID, elem) {
        if (confirm("确认移除？")) {
            $.post("{:U('Book/ycwz')}",
                    {ID: ID},
                    function (data) {
                        if (data == 1) {
                            alert('移除成功');
                            elem.parent().parent().remove();
                        } else {
                            alert('移除失败');
                        }
                    });
        }

    }


    $(document).ready(function () {
        $('#dataTables-example').DataTable({
            responsive: true
        });
    });
</script>
<script>
    <!--全选择框-->
    $("#all_checkbox").click(function () {
        if ($(this).is(':checked')) {
            $("input[name='checkbox']").prop("checked", "true");
        } else {
            $("input[name='checkbox']").removeAttr("checked", false);

        }
    })
    function checkboxID() {
        var vals = [];
        $("input[name='checkbox']:checkbox:checked").each(function (index, item) {
            vals.push($(this).val());
        });
        if (vals.length <= 0) {
            alert('请选择书籍');
            return 0;
        }
        $.post("{:U('Basket/AddAll')}",
                {IDS: vals},
                function (data) {
                    console.log(data);
                    if (parseInt(data)) {
                        alert('导入书篮子成功');
                        $("input[name='checkbox']:checkbox:checked").each(function (index, item) {
                            $(this).hide();
                        });
                    } else {
                        alert('导入书篮子失败');
                        window.location.reload()
                    }

                });
    }


    function updateSTOCK(ID, elem, top) {
        $.post("{:U('Book/updateSTOCK')}",
                {ID: ID, top: top},
                function (data) {
                    if (parseInt(data) >= 0) {
                        if (top == 1) {
                            elem.next().html(data);
                        } else {
                            elem.prev().html(data);
                        }
                    } else {
                        alert('修改失败,库存不能小于0');
                        window.location.reload()
                    }
                });
    }

    function del(ID, $elem) {
        if (confirm("确认删除？")) {
            $.post("{:U('delete')}",
                    {ID: ID},
                    function (data) {
                        if (parseInt(data) == 1) {
                            $elem.parent().parent().remove();
                            alert('删除成功');
                        } else {
                            alert('删除失败');
                        }
                    });
        }
    }
</script>
</body>

</html>
